package korkd.tower;

import java.util.LinkedList;

import org.anddev.andengine.entity.layer.tiled.tmx.TMXTiledMap;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.pool.GenericPool;

public class ArmyPool extends GenericPool<Army> {

	private TiledTextureRegion mTextureRegion;
	private Scene mScene;
	private LinkedList<Army> mArmyList = new LinkedList<Army>();
	private Player mPlayer;
	private TMXTiledMap mTMXTiledMap;
	
	ArmyPool(TiledTextureRegion pTextureRegion, Scene pScene, Player pPlayer, TMXTiledMap pTMXTiledMap)
	{
		mTextureRegion = pTextureRegion;
		mScene = pScene;
		mPlayer = pPlayer;
		mTMXTiledMap = pTMXTiledMap;
	}
	
	@Override
	protected Army onAllocatePoolItem() {
		Army tArmy = new Army(0, 0, mTextureRegion.deepCopy(), mPlayer, this, mTMXTiledMap);
		mScene.attachChild(tArmy);
		return tArmy;
	}
	
	@Override
	protected void onHandleRecycleItem(final Army pArmy)
	{
		pArmy.setIgnoreUpdate(true);
		pArmy.setVisible(false);
		mArmyList.remove(pArmy);
	}
	
	@Override
	protected void onHandleObtainItem(final Army pArmy)
	{
		mArmyList.add(pArmy);
		pArmy.reset();
	}
	
	public LinkedList<Army> getArmyList()
	{
		return mArmyList;
	}

}
